package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import client.ClientBean;
import dao.ClientDAO;

public class AddClient extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String email = request.getParameter("email");
		
		
		ClientBean c =null;
		ClientDAO cd;
		
		if (id!=null) {
			c = new ClientBean(id, name, email);
			cd = new ClientDAO();
			cd.addClient(c);
		}
						
		PrintWriter pw = response.getWriter();

		pw.println("<html>");
		pw.println("<body>");
		if (c != null)	pw.println("Client " + c.getName() + " added succefully!");	
		else pw.println("Error: client not created.");
		pw.println("</body>");
		pw.println("</html>");
		
	}

}
